/*
 * @Author: minglic minglic@foxmail.com
 * @Date: 2023-10-21 09:20:16
 * @LastEditors: minglic minglic@foxmail.com
 * @LastEditTime: 2023-10-21 11:29:55
 * @FilePath: \go2023\admin\internal\controller\site.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package controller

import (
	"github.com/gin-gonic/gin"
	"sxk.games/m/v2/admin/internal/service"
	"sxk.games/m/v2/core/entity"
	"sxk.games/m/v2/core/utils"
)

//添加泵站
func SiteCreate(c *gin.Context) {
	var reqData entity.Site
	var result any
	var err error

	//从上下文中解析出请求数据
	if err = c.ShouldBindJSON(&reqData); err == nil {
		//调用创建的业务逻辑
		result, err = service.Impl.Site.Create(&reqData)
	}

	//封装响应数据返回给前端
	utils.ResponseJson(c, err, result)
}

//删除泵站
func SiteDelete(c *gin.Context) {
	var reqData entity.DtoId
	var result any
	var err error

	if err = c.ShouldBindJSON(&reqData); err == nil {
		result, err = service.Impl.Site.Delete(reqData.Id)
	}

	utils.ResponseJson(c, err, result)
}

//查询泵站
func SiteList(c *gin.Context) {
	var reqData entity.DtoKeyword
	var result any
	var err error

	if err = c.ShouldBindJSON(&reqData); err == nil {
		result, err = service.Impl.Site.List(reqData.Keyword, reqData.Page, reqData.Size)
	}

	utils.ResponseJson(c, err, result)
}

//查询泵站
func SiteUpdate(c *gin.Context) {
	var reqData entity.Site
	var result any
	var err error

	if err = c.ShouldBindJSON(&reqData); err == nil {
		result, err = service.Impl.Site.Update(&reqData)
	}

	utils.ResponseJson(c, err, result)
}
